


package org.hive.hive;
import java.io.InputStream;

import org.apache.commons.io.IOUtils;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup.LayoutParams;
import android.widget.Button;
import android.widget.EditText;

public class GeoTag extends Activity implements OnClickListener {
	Button TakePicture,ViewPictures,GetRecommendation,CreateTrail;
    /** Called when the activity is first created. */
    @Override
        public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
        TakePicture=(Button)findViewById(R.id.TakePicture);
        ViewPictures=(Button)findViewById(R.id.ViewPictures);
        GetRecommendation=(Button)findViewById(R.id.GetRecommendation);
        CreateTrail = (Button)findViewById(R.id.newtrail);
        
        TakePicture.setOnClickListener(this);
        ViewPictures.setOnClickListener(this);
        GetRecommendation.setOnClickListener(this);
        CreateTrail.setOnClickListener(this);
        
    }
	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub
		Intent i;
		switch(v.getId())
		{
		case R.id.TakePicture:
			i=new Intent(this,location.class);
			startActivity(i);
			break;
		case R.id.ViewPictures:
			i=new Intent(this,DisplayPictures.class);
			startActivity(i);
			break;
		case R.id.GetRecommendation:
			i=new Intent(this,Recommendation.class);
			startActivity(i);
			break;
		case R.id.newtrail:
		{
			final AlertDialog alertDialog = new AlertDialog.Builder(GeoTag.this).create();
			final EditText tempCreateTrail = new EditText(this);
			tempCreateTrail.setLayoutParams(new LayoutParams(50,20));
			alertDialog.setView(tempCreateTrail);
			alertDialog.setTitle("Create New Trail ? ");
			//alertDialog.setMessage("R u sure?");
			
			alertDialog.setButton("OK", new DialogInterface.OnClickListener() {
			      public void onClick(DialogInterface dialog, int which ) {
			    	String albumName = tempCreateTrail.getText().toString();
			    	try{
			    	HttpClient hc = new DefaultHttpClient();
					HttpPost post = new HttpPost(Global.URL+"MobileCreateTrail?userid="+Global.userid+"&trailname="+albumName);

					HttpResponse rp = hc.execute(post);

					InputStream in = rp.getEntity().getContent();
					int tempalbumid = Integer.parseInt(IOUtils.toString(in));
					Global.albumlist.put(albumName, new Integer(tempalbumid));
			    	}
			    	catch(Exception e)
			    	{
			    		e.printStackTrace();
			    	}
			    } }); 
			alertDialog.setButton(DialogInterface.BUTTON_NEGATIVE,"Cancel", new DialogInterface.OnClickListener() {
			      public void onClick(DialogInterface dialog1, int which1) {
			    	
			    	//alertDialog.dismiss();
			 
			    } }); 
			alertDialog.show();
		}
	}
}
}